<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
            list-style: none;
        }
        ul {
            width: 900px;
            background-color: pink;
            display: flex;
            flex-wrap:wrap;
        }
        ul li {
            width: 300px;
            height: 100px;
        }
    </style>
</head>
<body>
    <ul>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
    </ul>

    <script>
        let li = document.querySelectorAll('li');

        function changeNumber (number) {
            return Math.floor(Math.random()*(number+1))
        }
        for (let i = 0; i < li.length; i++) {
            const element = li[i];
            element.onclick = function(evt) {
                bgColor = `rgb(${changeNumber(255)},${changeNumber(255)},${changeNumber(255)})`
                evt.target.style.background = bgColor
            }
            
        }
    </script>
</body>
</html>